 require("tsp")
  
  
t={}
game={}
degree = 90
t['事件_用户协议_未勾选'] = { 0x313431, "0|0|0x313431,162|63|0x393c39,213|51|0x8c8e8c,248|56|0x000000,74|-165|0x6b6973", degree, 259, 108, 693, 434 }
t['事件_用户协议_好的'] = { 0x39f300, "0|0|0x39f300,-132|-51|0x7bff00,-136|-63|0x313431", degree, 280, 115, 590, 417 }
t['事件_章结x'] = { 0x5a3418, "0|0|0x5a3418,9|-7|0x5a3410,-9|-8|0x5a3418,-1|-16|0xc68a29,1|15|0xc68629", degree, 889, 12, 949, 104 }
t['事件_章结领取'] = { 0x39ef00, "0|0|0x39ef00,-62|-17|0x42ef00,58|18|0x08e700", degree, 176, 426, 361, 496 }

game.event = function ()
    arr = {'事件_用户协议_未勾选','事件_用户协议_好的', "事件_章结领取", "事件_章结x"}
    for k,v in ipairs(arr) do
        if v == '事件_章结x' then
            if d(v) then
                click(269,462)
            end
        end
        
        if d(v,true) then
            return true
        end
    end
end


t['弹窗_对话跳过'] = { 0xb5b2b5, "0|0|0xb5b2b5,-126|337|0xefb600", degree, 768, 8, 954, 365 }
t['弹窗_跳过->'] = { 0xb5b2b5, "0|0|0xb5b2b5,-4|-1|0x000000,-1|10|0x000000,-2|-7|0xb5b2b5", degree, 925, 1, 954, 36 }
t['弹窗_引导_绿按钮'] = { 0x18eb00, "0|0|0x18eb00,-77|-31|0x42ef00,-88|-32|0x000000,65|12|0x08eb00", degree, 148, 68, 808, 494 }
t['弹窗_引导_右下角绿按钮'] = { 0x63ff18, "0|0|0x63ff18,-72|-20|0x42ef00,-79|-20|0x000000,72|2|0x31ef00", degree, 729, 426, 923, 532 }
t['弹窗_引导_蓝按钮'] = { 0x00cbe7, "0|0|0x00cbe7,-69|-35|0x00cfef,-75|-35|0x000000,76|8|0x00c7e7", degree, 84, 41, 908, 515 }
t['弹窗_引导_蓝按钮2'] = { 0x00cfef, "0|0|0x00cfef,-73|-26|0x00cfef,70|21|0x00c7e7,11|-9|0x004973", degree, 61, 79, 819, 539 }
t['弹窗_引导_红绿勾'] = { 0x7bff00, "0|0|0x7bff00,16|-15|0x7bff00,-95|-6|0xff2421,-102|-14|0xff2421", degree, 24, 10, 939, 526 }
t['弹窗_引导_攻击红按钮'] = { 0xf70c10, "0|0|0xf70c10,-72|-23|0xff1410,-78|-24|0x002400,71|18|0xef0000", degree, 7, 5, 944, 525 }
t['弹窗_关闭按钮'] = { 0xffffff, "0|0|0xffffff,19|-17|0xff1410,-21|-16|0xff1410,-12|13|0x000000,-21|20|0xef0000", degree, 589, 44, 949, 220 }
t['弹窗_返回按钮'] = { 0xffffff, "0|0|0xffffff,29|0|0x6b6973,-25|-16|0x6b6973,-24|10|0x6b6973", degree, 6, 1, 149, 79 }
t['弹窗_引导_上兵'] = { 0x423839, "0|0|0x423839,12|-7|0x181818,-859|-246|0x393c39,-86|220|0x003039,30|226|0x003039", degree, 14, 11, 951, 531 }
t['弹窗_可点击'] = { 0x31ef00, "0|0|0x31ef00,71|20|0x10e700,-318|22|0xffcb29,68|-382|0xffffff,85|-378|0xff1010", degree, 422, 53, 868, 495 }
t['返回_科林的探索'] = { 0x394139, "0|0|0x394139,32|-12|0xefffce,-31|-22|0xdeff6b,-346|-154|0xffdb4a,-351|-163|0xffef94", degree, 3, 4, 469, 330 }
t['返回_科林的探索_前往'] = { 0x31ef00, "0|0|0x31ef00,-4|-3|0x005510,-89|-29|0x42ef00,89|24|0x08e700,-758|-245|0xffdb4a,-764|-253|0xffeb8c", degree, 5, 1, 922, 409 }
t['事件_挑战失败'] = { 0x39b2ff, "0|0|0x39b2ff,80|-88|0x210400,100|-129|0x105184,309|5|0x31aaf7,-131|-1|0x39aeff", degree, 176, 49, 781, 496 }
t['事件_快速使用提示'] = { 0x29eb00, "0|0|0x29eb00,3|-1|0x005510,-60|-76|0xffcf29,56|-98|0xffdb29,78|-159|0xffffff,60|-140|0xef0000", degree, 617, 35, 897, 267 }

game.tips = function ()
    arr = {"事件_快速使用提示", "事件_挑战失败", "返回_科林的探索", "返回_科林的探索_前往", "弹窗_返回按钮", "弹窗_可点击", "弹窗_关闭按钮", '弹窗_跳过->', '弹窗_引导_绿按钮', "弹窗_引导_右下角绿按钮", "弹窗_引导_蓝按钮",
        "弹窗_引导_蓝按钮2",
        "弹窗_引导_红绿勾", "弹窗_引导_攻击红按钮", "弹窗_引导_上兵",  }
    for k,v in ipairs(arr) do
        if d(v,true) then
            log({x,y})
            if v == "事件_挑战失败" then
                appinfo.armKey = true
            elseif v == "返回_科林的探索_前往" then
                delay(2)
                d("攻击提示_攻击", true)
                delay(2)
                d("攻击提示_行军", true)
            end
            
            return true
        end
    end
end

t['手指_向上'] = { 0xefb2a5, "0|0|0xefb2a5,18|44|0x4a2021,29|32|0x8c414a,42|71|0x633431,-2|37|0xce8e73,52|22|0xf7dbde", degree, 26, 4, 924, 526 }
t['手指_向左'] = { 0xefaa9c, "0|0|0xefaa9c,35|-1|0xd6927b,48|-18|0x633031,71|-49|0x633431,19|-53|0xf7dbde,34|-43|0x844952", degree, 21, 8, 807, 528 }
t['手指_向左_上'] = { 0xefb6a5, "0|0|0xefb6a5,5|-3|0xde9273,43|-18|0x391c18,46|-9|0xbd795a,79|-39|0x633431", degree, 461, 0, 720, 158 }
t['手指_向下'] = { 0xefb29c, "0|0|0xefb29c,6|-35|0xa56152,-46|-68|0x633431,-52|-20|0xf7dbde", degree, 31, 243, 943, 528 }
t['手指_向上滑动'] = { 0xa5ffff, "0|0|0xa5ffff,92|-135|0xa5ffff,81|-128|0xa57542", degree, 178, 247, 457, 501 }
t['手指_右下'] = { 0xefb2a5, "0|0|0xefb2a5,-34|-12|0xc6826b,-38|-18|0x632421,-36|-29|0x391c18,-69|-51|0x6b3c39,-57|4|0xf7dbde,-59|-6|0x733439", degree, 50, 11, 926, 515 }
t['手指_右上'] = { 0xefb2a5, "0|0|0xefb2a5,-36|-2|0xd68e73,-44|18|0x522429,-51|18|0x733431,-20|51|0xf7dbde,-77|38|0x6b3839,-81|41|0xce8e18", degree, 450, 9, 950, 532 }
t['降落城堡_'] = { 0xffffff, "0|0|0xffffff,-5|-12|0xffffff,-26|118|0xefa68c,-7|156|0x84454a", degree, 380, 131, 585, 407 }
    t['降落城堡_传送'] = { 0x08fbff, "0|0|0x08fbff,11|-126|0x00f3ff,-141|-132|0x087d94,-139|3|0x00f3ff", degree, 290, 89, 653, 443 }
    t['降落城堡_传送选择地址'] = { 0x000000, "0|0|0x000000,7|0|0xffffff,55|-22|0x009e08,59|54|0xff1410,202|100|0xef0000", degree, 9, 7, 874, 523 }
    t['降落城堡_确定传送'] = { 0x31ef00, "0|0|0x31ef00,6|1|0x005510,-108|-20|0xff1410,-246|14|0xef0400,-71|-23|0x42ef00", degree, 16, 13, 872, 517 }

game.arrow = function()
    arr = {"手指_向上滑动", "手指_向上", "手指_向左", "手指_向下", "手指_向左_上","手指_右下", "降落城堡_", "降落城堡_传送", "降落城堡_传送选择地址" }
    keepScreen(true)
    for k,v in ipairs(arr) do
        if d(v,true) then
            if v == "手指_向上滑动" then
                moveTo(324, 390,569, 246,5)
            elseif v == "手指_右下" then
                for i=1,4 do
                    click(x+i*80,y+i*50)
                end
            elseif v == "手指_向左" then
                for i=1,4 do
                    click(x-i*80,y+i*50)
                end
            elseif v == "降落城堡_" then
                touchDown(1,484,273)
                delay(2)
                touchUp(1,484,273)
            elseif v == "降落城堡_传送2" then
                click(x-80,y)
            elseif v == "降落城堡_传送选择地址" then
                moveTo(x,y,x+math.random(-50,50),y+math.random(-50,50))
                d("降落城堡_确定传送", true)
            end
            log({x,y})
            return true
        end
    end
    keepScreen(false)
end

t['游戏正常'] = { 0xe7aa4a, "0|0|0xe7aa4a,26|-77|0xf7c784,27|-77|0xbd8a39", degree, 9, 0, 86, 93 }
t['游戏正常_帮派帮助'] = { 0xe7d3ad, "0|0|0xe7d3ad,11|2|0xf7cf9c,17|6|0x313031,20|-13|0xd60000", degree, 694, 449, 780, 537 }
t['游戏正常_帮派帮助2'] = { 0xe7dbb5, "0|0|0xe7dbb5,14|8|0x313031,19|-14|0xd60000", degree, 780, 442, 877, 535 }
t['游戏正常_挑战准备界面'] = { 0x004973, "0|0|0x004973,-4|-7|0x00cfef,-829|-469|0xffffff", degree, 5, 1, 956, 536 }
    t['游戏正常_快速选择'] = { 0x004973, "0|0|0x004973,93|4|0x004973,-27|-27|0x00cff7,337|19|0x08e700", degree, 449, 422, 834, 488 }
    t['游戏正常_确定'] = { 0x005510, "0|0|0x005510,-79|-21|0x42ef00,58|17|0x10e700", degree, 648, 408, 845, 502 }
    t['游戏正常_挑战_有门'] = { 0xf779f7, "0|0|0xf779f7,-11|-13|0x4234bd,2|-32|0xffffff", degree, 94, 403, 203, 539 }
    
t['战斗画面中'] = { 0xffd74a, "0|0|0xffd74a,1|20|0xe7aa29,-465|-1|0xffffff", degree, 7, 1, 616, 78 }

game.home = function()
    if d("游戏正常") then
        d("游戏正常_帮派帮助", true)
        d("游戏正常_帮派帮助2", true)
        return true
    elseif d("游戏正常_挑战准备界面") then
        if d("游戏正常_挑战_有门", true) then
            click(572,389,2)
            click(574,423,2)
        end
        click(893,269)
        d("游戏正常_快速选择",true)
        d("游戏正常_确定",true)
        d("游戏正常_挑战准备界面",true)
        return true
    elseif d("战斗画面中")then
        return true
    end
end

t['升级提示'] = { 0x7bff00, "0|0|0x7bff00,0|13|0x7bff00,-44|49|0xe7f7c6,43|-56|0xf7ffce", degree, 218, 46, 800, 459 }
t['升级提示2'] = { 0x7bff00, "0|0|0x7bff00,47|-43|0xf7ffce,-45|40|0xffffd6,-45|-31|0xffffd6,48|29|0xdeff63", degree, 224, 213, 700, 466 }
    t['升级提示_升级按钮'] = { 0x39ef00, "0|0|0x39ef00,-123|-21|0x42ef00,44|33|0x00a600", degree, 636, 393, 866, 512 }
    t['升级提示_发送帮助'] = { 0x398ead, "0|0|0x398ead,-23|2|0x398ead,-33|4|0xffffff,-11|11|0xffffff", degree, 250, 59, 760, 440 }
    
t['训练提示'] = { 0x00f3ff, "0|0|0x00f3ff,48|42|0xd6f74a,-47|-37|0xd6fb4a,-47|31|0xd6fb4a,47|-34|0xefffa5", degree, 141, 57, 902, 481 }
t['训练提示2'] = { 0x00f3ff, "0|0|0x00f3ff,-46|-33|0xf7ffce,-46|39|0xf7ffce,46|-33|0xf7ffce,46|43|0xf7ffce", degree, 187, 154, 795, 489 }
t['酒馆提示'] = { 0xf7ffce, "0|0|0xf7ffce,169|6|0xe7ff73,167|-10|0xefff84", degree, 351, 240, 626, 309 }
    t['神秘商店'] = { 0xf7e74a, "0|0|0xf7e74a,-190|20|0xb51c18,-343|-2|0xadb6b5,-680|10|0xd6ae39", degree, 79, 421, 879, 521 }
        t['神秘商店_电池'] = { 0xe7fbff, "0|0|0xe7fbff,-4|3|0xffbe18,-2|9|0xad2029,0|-8|0x526da5", degree, 391, 163, 936, 396 }
        t['神秘商店_钢铁'] = { 0x7b96b5, "0|0|0x7b96b5,6|-5|0x7b96b5,6|-2|0x525142,-3|13|0x636173,0|10|0x7b92b5,-7|-6|0xffdb31", degree, 391, 163, 936, 396 }

t['研究界面'] = { 0x7bff00, "0|0|0x7bff00,659|-241|0xffffff,676|-255|0xff1410", degree, 109, 35, 873, 358 }
t['研究界面2'] = { 0x7bff00, "0|0|0x7bff00,426|-108|0xffffff,441|-125|0xff1410,444|-104|0xf71008,112|-5|0x000000", degree, 158, 10, 911, 270 }
    t['研究界面_军事面板'] = { 0xa5a2a5, "0|0|0xa5a2a5,-1|12|0xa5a2a5,17|13|0x4a4142,0|-81|0x212021,-10|-83|0xffc700", degree, 23, 100, 111, 277 }
        t['研究界面_升级小点'] = { 0x7bff00, "0|0|0x7bff00,23|-5|0x000000,100|-6|0x000000", degree, 117, 112, 319, 468 }

        
t['攻击提示'] = { 0x005510, "0|0|0x005510,-3|1|0x29eb00,-75|-27|0x42ef00,68|16|0x08e700", degree, 717, 423, 940, 531 }    
    t['攻击提示_攻击'] = { 0x7b0400, "0|0|0x7b0400,-77|-22|0xff1410,64|23|0xef0000,-47|21|0xef0000", degree, 26, 59, 934, 491 }
    t['攻击提示_行军'] = { 0x31eb00, "0|0|0x31eb00,-72|-25|0x42ef00,72|19|0x08e700,45|25|0x00a600,13|-11|0x005510", degree, 55, 17, 947, 518 }
t["加速提示"] = { 0xffc700, "0|0|0xffc700,19|0|0xffc700,-35|-46|0xffffd6,-35|21|0xffffd6,57|-36|0xf7ffce,57|17|0xf7ffce", degree, 228, 177, 813, 503 }    
t['入会提示'] = { 0xd63831, "0|0|0xd63831,-41|0|0xf7ffce,45|2|0xefffb5", degree, 769, 488, 888, 521 }
    t['入会提示_加入提示'] = { 0x00cfef, "0|0|0x00cfef,63|-18|0x00cfef,-7|2|0x004973,-174|-287|0xffe700", degree, 392, 56, 870, 482 }
    t['入会提示-输入'] = { 0xffffff, "0|0|0xffffff,-125|397|0xffdb29,489|377|0x00cfef,418|6|0x00cfef", degree, 9, 6, 939, 523 }
    t['入会提示-加入'] = { 0x004d7b, "0|0|0x004d7b,-80|-19|0x00cfef,56|23|0x00c7e7", degree, 734, 374, 953, 518 }
    t['入会提示-加入申请'] = { 0x00cfef, "0|0|0x00cfef,9|-2|0x004973,232|-302|0xffffff,251|-299|0xff1010", degree, 311, 56, 794, 488 }
    t['入会提示-礼物'] = { 0xe73c29, "0|0|0xe73c29,122|-17|0xd60000", degree, 7, 277, 181, 539 }
t['英雄升级'] = { 0xffffff, "0|0|0xffffff,9|12|0x08eb00,8|-9|0x42eb00,-183|-115|0x00cfef", degree, 707, 2, 956, 402 }    
    t["英雄升级_快速使用"] = { 0x29eb00, "0|0|0x29eb00,-64|-23|0x42ef00,61|15|0x08e700,4|-3|0x005510", degree, 609, 187, 853, 259 }
t['绝地试炼'] = { 0x004973, "0|0|0x004973,-2|0|0x00cfef,174|-326|0xffffff,191|-341|0xff1410", degree, 460, 52, 815, 453 }    
t['绝地试炼_界面'] = { 0xffe700, "0|0|0xffe700,247|-85|0xffe700,245|-2|0xffe700,3|-84|0xffe700,27|-156|0xffffff", degree, 3, 3, 288, 231 }    
    t['绝地试炼_最新挑战'] = { 0xffe74a, "0|0|0xffe74a,-14|2|0xffdb52,-8|0|0xfffb42", degree, 318, 85, 920, 464 }
    
game.task = function()
    click(86,176,2)
    if d("升级提示", true) or d("升级提示2", true) then
        d("升级提示_升级按钮", true)
        d("升级提示_发送帮助", true)
        
    elseif d("训练提示", true) or d("训练提示2", true) then
        if d("神秘商店") then
            d("神秘商店_电池",true)
            d("神秘商店_钢铁",true)
        elseif d("研究界面") or d("研究界面2",true) then
            d("研究界面_军事面板",true)
            d("研究界面_升级小点",true)
        else
            d("升级提示_升级按钮", true)
            if d("酒馆提示",true) then
                click(493,253)
            end
        end
    elseif d("攻击提示", true) then
        delay(2)
        d("攻击提示_攻击", true)
        delay(2)
        d("攻击提示_行军", true)
    elseif d("加速提示", true,1,3) then
        d("英雄升级_快速使用",true)
    elseif d("入会提示", true) then
        if d("入会提示_加入提示", true) then
            delay(5)
            d("入会提示-输入", true)
            input("Kmm")
            click(709,86)
            click(709,86)
            d("入会提示-加入",true)
            d("入会提示-加入申请",true)
        else
            d("入会提示-礼物",true)
            d("弹窗_引导_绿按钮",true)
        end
    elseif d("英雄升级",true) then
        d("英雄升级_快速使用",true)
        d("英雄升级_快速使用",true)
        d("英雄升级_快速使用",true)
        d("英雄升级_快速使用",true)
        d("英雄升级_快速使用",true)
    elseif d("绝地试炼", true) or d("绝地试炼_界面") then
        d("绝地试炼_最新挑战",true)
        d("绝地试炼", true)
    end
end


t['游戏_建造'] = { 0xe7b67b, "0|0|0xe7b67b,-3|2|0xf7efef,20|-25|0xd60000", degree, 7, 369, 83, 438 }
    t['游戏_建造_可以建造'] = { 0x5a5963, "0|0|0x5a5963,-3|-1|0xffffff,-10|1|0x5a5963,-18|-5|0xffffff", degree, 131, 389, 303, 530 }
        t['游戏_建造_建造'] = { 0x7bff00, "0|0|0x7bff00,19|-18|0x7bff00,-89|5|0xff2421,-102|-18|0xf72829,-96|2|0xe72021", degree, 173, 119, 821, 449 }
    t['消除红点'] = { 0xa5a2a5, "0|0|0xa5a2a5,-10|-35|0xd60000", degree, 24, 364, 71, 426 }
    
    
game.biuld = function()
    if d("游戏_建造", true) then
        if not(d("游戏_建造_可以建造", true)) then
            d("消除红点",true)
        end
        d("游戏_建造_建造", true)
    end
end



t['奖励提示'] = { 0xffffe7, "0|0|0xffffe7,7|-11|0xd60000", degree, 14, 197, 58, 237 }
    t['奖励_领取'] = { 0x31ef00, "0|0|0x31ef00,-56|-18|0x42ef00,55|15|0x08eb00", degree, 686, 131, 849, 460 }
    t['奖励_左侧'] = { 0x4a4142, "0|0|0x4a4142,25|-18|0x4a4142,-1|-20|0xd60000", degree, 26, 112, 100, 353 }
t['奖励_活动'] = { 0xffffff, "0|0|0xffffff,-2|2|0xfff34a,-22|4|0x101008", degree, 199, 150, 796, 183 }    
    t['奖励_贝壳'] = { 0x393018, "0|0|0x393018,-20|-29|0x7b6d5a,-35|-21|0x7b6d5a,-36|5|0xfff739", degree, 204, 161, 849, 484 }
    t['奖励_贝壳2'] = { 0xffffff, "0|0|0xffffff,-17|14|0xffef31,20|12|0xffef31,-2|-13|0xde9a73", degree, 202, 167, 844, 484 }
    t['奖励_包箱'] = { 0xffffff, "0|0|0xffffff,-4|2|0xd69610,-45|22|0xf7cb21,-52|24|0xf7cb21", degree, 204, 161, 849, 484 }
game.award = function()
    if d("奖励提示", true) then
        local i = 0
        while ( d("奖励_领取", true) or d("奖励_活动",true) or  d("奖励_贝壳",true)  or d("奖励_贝壳2",true)  or d("奖励_包箱",true) or d("奖励_左侧", true) ) and i < 10 do
        
            i=i+1
        end
        d("弹窗_关闭按钮",true)
    end
end


t['正常_城内'] = { 0xc61c18, "0|0|0xc61c18,-15|9|0x8c9639,-16|-77|0x949e8c,-22|-67|0xe7b67b", degree, 18, 388, 75, 488 }
t['正常_野外'] = { 0xbdff29, "0|0|0xbdff29,18|-9|0xceb6ad,16|-76|0x63aea5,2|-60|0xb5794a", degree, 19, 376, 69, 506 }
game.init = function()
    local i = 0
    returnKey = false
    while i < 30 do
        if returnKey and d("正常_城内") then
            return true
        elseif d("正常_城内") then
            click( 48,487,2 )
            click( 48,487,2 )
            if d("正常_城内") then
                returnKey = true
            end
        elseif d("正常_野外", true) then
            returnKey = true
        end
        i = i+1
        delay(1)
    end
end


t['训练_轮子'] = { 0x00f3ff, "0|0|0x00f3ff,-88|10|0x7bff00,-87|33|0x7bff00,-175|15|0x00f3ff,-176|-14|0x00f3ff", degree, 136, 53, 905, 490 }
t['训练_加速'] = { 0x00f3ff, "0|0|0x00f3ff,-77|18|0xffc700,-96|20|0xffc700,-173|-13|0x00f3ff,-173|14|0x00f3ff", degree, 131, 45, 896, 482 }

game.arm = function()
    arm_lun = arm_lun or 0
    arm_lun = arm_lun + 1
    if game.init() then
        if arm_lun%2== 0 then
            click(355,354,2)
        else
            click(741,135,2)
        end
        if d("训练_加速", true) then
            d("英雄升级_快速使用",true)
        elseif d("训练_轮子", true) then
            appinfo.armLun = appinfo.armLun + 1
            if appinfo.armLun > 8 then
                appinfo.armLun = 0
                appinfo.armKey = false
            end
        end
    end
end


appinfo = {}
appinfo.bid = "com.mkbanana.gp"
appinfo.armKey = false
appinfo.armLun = 0


lun = 0
other = 0
while (true) do
    if active(appinfo.bid, 5) then
        if game.home() then
            game.biuld()
            game.award()
            
            if appinfo.armKey  then
                game.arm()
            else
                game.task()
            end
        
        elseif not( game.tips() ) then
            log("无tips")
            if not( game.event() ) then
                log("无event")
                game.arrow()
                other = other + 1
                if other % 3 == 0 then
                    log("点一下空白")
                    click(80,80)
                end
            end
        end
        
        lun = lun + 1
        if lun%3== 0 then
            game.arrow()
        elseif lun%5 ==0 then
            click(480,295)
        end
        mSleep(1000)
    end
end

































